package com.kingwang.training.designpattern.exam.dao.impl;

import com.kingwang.training.designpattern.exam.bo.DepartmentContact;
import com.kingwang.training.designpattern.exam.bo.Notice;
import com.kingwang.training.designpattern.exam.bo.Task;
import com.kingwang.training.designpattern.exam.dao.TaskDao;
import org.springframework.stereotype.Repository;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author King
 */
@Repository
public class TaskDaoImpl implements TaskDao {
    private Map<UUID, Task> tasks = new ConcurrentHashMap<>();

    private Map<UUID, Notice> notices = new ConcurrentHashMap<>();

    private Map<UUID, DepartmentContact> departmentContacts = new ConcurrentHashMap<>();

    @Override
    public UUID addTask(Task task) {
        if (task.getId() == null) {
            task.setId(UUID.randomUUID());
        }

        this.tasks.put(task.getId(), task);

        return task.getId();
    }

    @Override
    public Task getTaskById(UUID id) {
        return this.tasks.get(id);
    }

    @Override
    public void updateTask(Task task) {
        // 内存实现，啥都不干
    }

    @Override
    public UUID addDepartmentContact(DepartmentContact contact) {
        if (contact.getId() == null) {
            contact.setId(UUID.randomUUID());
        }

        this.departmentContacts.put(contact.getId(), contact);

        return contact.getId();
    }

    @Override
    public DepartmentContact getProductDepartmentContact() {
        return this.departmentContacts.values().stream().findFirst().get();
    }

    @Override
    public UUID addNotice(Notice notice) {
        if (notice.getId() == null) {
            notice.setId(UUID.randomUUID());
        }

        this.notices.put(notice.getId(), notice);

        return notice.getId();
    }
}
